﻿using System.Windows;
using ImageAppViewModels;

namespace WpfImageDuplicates
{
    /// <summary>
    /// Interaction logic for FullViewerWindow.xaml
    /// </summary>
    public partial class ImageCollectionWindow : Window
    {
        public static readonly DependencyProperty FileImageCollectionViewModelProperty =
        DependencyProperty.Register("FileImageCollectionViewModel", typeof(FileImageCollectionViewModel), typeof(ImageCollectionWindow), new PropertyMetadata(null, OnFileImageCollectionViewModelPropertyChanged));

        public FileImageCollectionViewModel FileImageCollectionViewModel
        {
            get { return (FileImageCollectionViewModel)GetValue(FileImageCollectionViewModelProperty); }
            set { SetValue(FileImageCollectionViewModelProperty, value); }
        }

        private static void OnFileImageCollectionViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ImageCollectionWindow source = d as ImageCollectionWindow;
            FileImageCollectionViewModel vNew = e.NewValue as FileImageCollectionViewModel;
            FileImageCollectionViewModel vOld = e.OldValue as FileImageCollectionViewModel;
            source.UpdateFileImageCollectionViewModel(vNew, vOld);
        }

        private void UpdateFileImageCollectionViewModel(FileImageCollectionViewModel viewModel, FileImageCollectionViewModel viewModelOld)
        {
            FileImageCollectionViewModel = viewModel;
            this.DataContext = FileImageCollectionViewModel;
        }

        public ImageCollectionWindow()
        {
            InitializeComponent();
            Closing += new System.ComponentModel.CancelEventHandler(ImageCollectionWindow_Closing);
        }
        
        void ImageCollectionWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Closing -= ImageCollectionWindow_Closing;
        }
    }
}
